package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.PlamtwithdrawdetailService;
import com.youi.entity.Plamtwithdrawdetail;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 平台提现申请详情控制层
* @author Administrator
*/
@Controller
public class PlamtwithdrawdetailController  extends HttpRequestManage{

		@Autowired
		private PlamtwithdrawdetailService plamtwithdrawdetailService;

		/**
		 *添加或编辑平台提现申请详情
		*/
		@ResponseBody
		@RequestMapping("addOrEditPlamtwithdrawdetail")
		public String addOrEditPlamtwithdrawdetail(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=optLong("id",request);
			Plamtwithdrawdetail plamtwithdrawdetail=null;
			if (id!=null) {
				plamtwithdrawdetail=plamtwithdrawdetailService.get(id);
			}else {
				plamtwithdrawdetail=new Plamtwithdrawdetail();
				plamtwithdrawdetail.setDelStatus(DelStatus.NODEL);
				plamtwithdrawdetail.setGmtCreated(new Date());
			}
			Long plamtwithdrawId=optLong("plamtwithdrawId",request);
			if (plamtwithdrawId!=null){
				plamtwithdrawdetail.setPlamtwithdrawId(plamtwithdrawId);
			}
			Integer status=optInteger("status",request);
			if (status!=null){
				plamtwithdrawdetail.setStatus(status);
			}
			String orderNo=optString("orderNo",request);
			if (orderNo!=null){
				plamtwithdrawdetail.setOrderNo(orderNo);
			}
			Double orderAmount=optDouble("orderAmount",request);
			if (orderAmount!=null){
				plamtwithdrawdetail.setOrderAmount(orderAmount);
			}
			Double serviceCharge=optDouble("serviceCharge",request);
			if (serviceCharge!=null){
				plamtwithdrawdetail.setServiceCharge(serviceCharge);
			}
			Double merchantRatio=optDouble("merchantRatio",request);
			if (merchantRatio!=null){
				plamtwithdrawdetail.setMerchantRatio(merchantRatio);
			}
			Double merchantAmount=optDouble("merchantAmount",request);
			if (merchantAmount!=null){
				plamtwithdrawdetail.setMerchantAmount(merchantAmount);
			}
			Double platformRatio=optDouble("platformRatio",request);
			if (platformRatio!=null){
				plamtwithdrawdetail.setPlatformRatio(platformRatio);
			}
			Double platformAmount=optDouble("platformAmount",request);
			if (platformAmount!=null){
				plamtwithdrawdetail.setPlatformAmount(platformAmount);
			}
			Double leaderRatio=optDouble("leaderRatio",request);
			if (leaderRatio!=null){
				plamtwithdrawdetail.setLeaderRatio(leaderRatio);
			}
			Double leaderAmount=optDouble("leaderAmount",request);
			if (leaderAmount!=null){
				plamtwithdrawdetail.setLeaderAmount(leaderAmount);
			}
			Double platformSum=optDouble("platformSum",request);
			if (platformSum!=null){
				plamtwithdrawdetail.setPlatformSum(platformSum);
			}
			plamtwithdrawdetail.setGmtModify(new Date());
			plamtwithdrawdetailService.saveOrUpdate(plamtwithdrawdetail);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}

		/**
		 *批量删除平台提现申请详情
		*/
		@ResponseBody
		@RequestMapping("delPlamtwithdrawdetailByIds")
		public String delPlamtwithdrawdetailByIds(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			String ids=getString("ids",request);
			List<Long> idsList=ObjectUtil.getIdListByIds(ids);
			if (idsList==null||idsList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "ids参数错误");
			}
			Map<String, Object> params=new HashMap<String, Object>();
			params.put(Common.DELSTATUS, DelStatus.NODEL);
			params.put(Common.ID, idsList);
			List<Plamtwithdrawdetail> plamtwithdrawdetailList= plamtwithdrawdetailService.getByParams(params);
			if (plamtwithdrawdetailList==null||plamtwithdrawdetailList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			for (Plamtwithdrawdetail plamtwithdrawdetail : plamtwithdrawdetailList) {
				plamtwithdrawdetail.setDelStatus(DelStatus.DEL);
			}
			plamtwithdrawdetailService.saveOrUpdateAll(plamtwithdrawdetailList);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}

		/**
		 * 分页查询平台提现申请详情
		*/
		@ResponseBody
		@RequestMapping("getPlamtwithdrawdetail")
		public String getPlamtwithdrawdetail(ModelMap modelMap,HttpServletRequest request) throws BusinessException,ParseException{
			Integer pageIndex=optInteger("pageIndex",request,1);
			Integer pageNum=optInteger("pageNum",request,10);
			String des=optString("des",request,Common.DESC);
			String pms=optString("pms",request);
			Date start=optDate("start",request,"yyyy-MM-dd HH:mm:ss");
			Date end=optDate("end",request,"yyyy-MM-dd HH:mm:ss");
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			Map<String, Object> sortPram=new HashMap<String, Object>();
			sortPram.put(Common.ID,des);
			Map<String, Object> searchPram=null;
			if (pms!=null) {
				searchPram=new HashMap<String, Object>();
			}
			Map<String, Object> startTime=null;
			if(start!=null){
				startTime=new HashMap<String, Object>();
				startTime.put(Common.GMTCREATED,start);
			}
			Map<String, Object> endTime=null;
			if(end!=null){
				endTime=new HashMap<String, Object>();
				endTime.put(Common.GMTCREATED,end);
			}
			List<Plamtwithdrawdetail> plamtwithdrawdetailList=plamtwithdrawdetailService.getByParamsList(prams, searchPram,sortPram,  (pageIndex-1)*pageNum, pageNum, startTime, endTime);
			if (plamtwithdrawdetailList==null||plamtwithdrawdetailList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			Integer pageCount=plamtwithdrawdetailService.getCountByParamss(prams, searchPram, startTime, endTime);
			modelMap.put(CommonInfoUtil.PAGECOUNT, Page.getCount(pageCount, pageNum));//pageCount  总页数
			modelMap.put(CommonInfoUtil.PAGEINDEX, pageIndex);			//pageIndex     查询页数
			modelMap.put(CommonInfoUtil.ALLCOUINT,pageCount);
			modelMap.put(CommonInfoUtil.DATA, plamtwithdrawdetailList);		//jsonObjectList json对象集合
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",modelMap);
		}

		/**
		 *根据id查询平台提现申请详情
		*/
		@ResponseBody
		@RequestMapping("getPlamtwithdrawdetailById")
		public String getPlamtwithdrawdetailById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Plamtwithdrawdetail plamtwithdrawdetail=plamtwithdrawdetailService.get(id);
			if (plamtwithdrawdetail==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",plamtwithdrawdetail);//jsonObject	json对象
		}

		/**
		 * 查询所有平台提现申请详情
		 * @param modelMap
		 * @param session
		 * @return
		 */
		@ResponseBody
		@RequestMapping("getAllPlamtwithdrawdetail")
		public String getAllPlamtwithdrawdetail(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			List<Plamtwithdrawdetail> plamtwithdrawdetailList= plamtwithdrawdetailService.getByParams(null);
			if (plamtwithdrawdetailList==null||plamtwithdrawdetailList.size()==0) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",plamtwithdrawdetailList);//jsonObjectList	json对象集合
		}
}
